package com.example.demo.common.utils.demo;

import com.example.demo.common.utils.BaseResponse;
import com.example.demo.common.utils.HttpUtil;
import com.example.demo.common.utils.RSAHelper;
import com.example.demo.common.utils.demo.common.Config;
import org.apache.commons.lang3.StringUtils;

/**
 * @author bear
 * @Description 对账单地址获取demo
 * @Date:2019/8/02 14:16
 */
public class Reconciliation {

    /**
     * 对账单地址获取
     */
    public static void companyReconciliation(String date) {
        String url = Config.baseUrl + "/open/api/v1/bill/companyReconciliation";
        String paramsJson = "{\"date\":\"" + date + "\"}";
        BaseResponse baseResponse = HttpUtil.post(url, paramsJson, Config.appKey, Config.secretkey, Config.publicKey);
        if (baseResponse.isSuccess()) {
            String rs = baseResponse.getData().toString();
            //公钥解密
            if (StringUtils.isNotBlank(rs)) {
                try {
                    String dec = RSAHelper.decryptByPublicKey(rs, Config.publicKey);
                    System.out.println(String.format("解密结果:%s", dec));
                } catch (Exception e) {
                    System.out.println("publicKey 有误");
                }
            }
        }
    }

    /**
     * 电子回单地址获取
     */
    public static void queryVoucherUrl(String thirdOrderId) {
        String url = Config.baseUrl + "/open/api/v1/bill/queryVoucherUrl";
        String paramsJson = "{\"thirdOrderId\":\"" + thirdOrderId + "\"}";
        BaseResponse baseResponse = HttpUtil.post(url, paramsJson, Config.appKey, Config.secretkey, Config.publicKey);
        if (baseResponse.isSuccess()) {
            String rs = baseResponse.getData().toString();
            //公钥解密
            if (StringUtils.isNotBlank(rs)) {
                try {
                    String dec = RSAHelper.decryptByPublicKey(rs, Config.publicKey);
                    System.out.println(String.format("解密结果:%s", dec));
                } catch (Exception e) {
                    System.out.println("publicKey 有误");
                }
            }
        }
    }
}
